// pages/common/gooddetails/gooddetails.js
Page({
  data: {
    bottomHeight: getApp().globalData.bottomHeight,
    id: "",
    swiperIndex: 1,
    detail: {},
    popup_show: false
  },
  onLoad: function (options) {
    this.setData({
      id: options.id
    });
    this.getDetail();
  },
  onShareAppMessage() {
    return {
      title: "邻小帮本地生活服务",
      imageUrl: "https://www.linxiaobang.com.cn/miniprogram/image/share.jpg",
    }
  },
  swiperChange(e) {
    this.setData({
      swiperIndex: e.detail.current + 1
    });
  },
  chat() {
    this.setData({
      popup_show: true
    });
  },
  toUser() {
    wx.setStorageSync("neighbor", {
      userId: this.data.detail.userId,
      userName: this.data.detail.userName,
      userAvatar: this.data.detail.userAvatar
    });
    wx.navigateTo({
      url: "/pages/user/user",
    })
  },
  getDetail() {
    getApp().globalData.http.detail({
      id: this.data.id
    }).then(res => {
      let tmp = res.data;
      tmp.imgIds = tmp.imgIds.split(",");
      tmp.imgUrls = tmp.imgUrls.split(",");
      this.setData({
        detail: res.data
      });
    });
  },
  call() {
    wx.makePhoneCall({
      phoneNumber: this.data.detail.type == 7 ? this.data.detail.tel : this.data.detail.mobile,
    })
  },
  previewImg(e) {
    getApp().globalData.util.previewImage(this.data.detail.imgUrls, e.currentTarget.dataset.img);
  }
})